package movie.ticketing.system.dao;

import movie.ticketing.system.model.User;
import movie.ticketing.system.util.SystemDB;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import static java.sql.DriverManager.getConnection;


public class UserDAO {
    String URL = SystemDB.URL;
    String USER = SystemDB.USER;
    String PASSWORD = SystemDB.PASSWORD;

    public void insertUser(User user) {// 插入用户
        String sql = "INSERT INTO user (user_name, password) VALUES (?, ?)";// SQL 插入语句
        try (Connection connection = getConnection(URL, USER, PASSWORD);// 获取数据库连接
             PreparedStatement preparedStatement = connection.prepareStatement(sql)) {//创建PreparedStatement对象预编译SQL语句

            preparedStatement.setString(1, user.getUserName());// 设置参数
            preparedStatement.setString(2, user.getUserPassword());// 设置参数
            preparedStatement.executeUpdate(); // 执行插入操作
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
    public void deleteUser(User user) {// 删除用户

    }
    public boolean selectUser(User user)  {// 查询用户

        return false;
    }
}
